home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wmotion.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  146 lines

  1. ; $Id: wmotion.pro,v 1.4 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for a draw widget that returns
  7. ; "motion events" when the cursor is moved over the 
  8. ; plotting window.  Don't be surprised if you select the
  9. ; 'Done' button and the X and Y coordinate labels 
  10. ; continue to change... a LOT of events will be 
  11. ; generated by moving the cursor over the window and
  12. ; it can take quite some time for the machine to catch
  13. ; up!
  14.  
  15.  
  16.  
  17. PRO wmotion_event, event
  18.  
  19. ; This is the event handler for a draw widget which tracks
  20. ; cursor motion events.
  21.  
  22. ; The COMMON block is used because the event handler needs
  23. ; widget ID's of the labels:
  24.  
  25. COMMON wmotionblock, x_label, y_label
  26.  
  27. ; When a widget is selected, put its User Value into 'eventval':
  28.  
  29. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  30.  
  31. ; Perform actions based on the User Value of the event:
  32.  
  33. CASE eventval OF
  34.    'DRAW_WIN_EVENT': BEGIN
  35.             ; The help statement is useful for
  36.             ; debugging the event handler.  Try uncommenting
  37.             ; it to see the full structure returned by a 
  38.             ; draw window event.  Note the 'PRESS' and
  39.             ; 'RELEASE' fields.
  40.             ; HELP, /STRUCT, event
  41.  
  42.             ; Only deal with the 'motion' event,
  43.             ; disregard the 'press' and 'release' events:
  44.  
  45.             IF (event.press EQ 0) AND (event.release EQ 0) THEN BEGIN
  46.                 ; Print the device coordinates of the cursor
  47.                 WIDGET_CONTROL, x_label, $
  48.                    SET_VALUE='X Coordinate: ' + STRING(event.x)
  49.  
  50.                 WIDGET_CONTROL, y_label, $
  51.                    SET_VALUE='Y Coordinate: ' + STRING(event.y)
  52.             ENDIF
  53.              END
  54.  
  55.    'DONE': WIDGET_CONTROL, event.top, /DESTROY
  56. ENDCASE
  57.  
  58. END
  59.  
  60.  
  61.  
  62. PRO wmotion, XSIZE=x_size, YSIZE=y_size, GROUP=GROUP
  63.  
  64. ; This is the procedure that creates a draw widget that returns
  65. ; motion events.
  66.  
  67. ; The COMMON block is used because the event handler needs
  68. ; widget ID's of the labels:
  69.  
  70. COMMON wmotionblock, x_label, y_label
  71.  
  72. swin = !D.WINDOW    ; Remember the current window so it can be restored
  73.  
  74.  
  75. ; This example uses keywords to define the size of the draw area:
  76.  
  77. if (NOT keyword_set(x_size)) THEN x_size = 300
  78. if (NOT keyword_set(y_size)) THEN y_size = 400
  79.  
  80. ; A top-level base widget with the title "Motion Event Widget Example"
  81. ; will be created.  The size is left unspecified until the draw widget
  82. ; is created:
  83.  
  84. base = WIDGET_BASE(TITLE = 'Motion Event Widget Example', $
  85.     /COLUMN)
  86.  
  87. ; Setting the managed attribute indicates our intention to put this application
  88. ; under the control of XMANAGER, and prevents our draw widgets from
  89. ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  90. ; sets this, but doing it here prevents our own WSETs at startup from
  91. ; having that problem.
  92. WIDGET_CONTROL, /MANAGED, base
  93.  
  94. ; The 'DONE' button:
  95.  
  96. button1 = WIDGET_BUTTON(base, $
  97.         UVALUE = 'DONE', $
  98.         VALUE = 'DONE')
  99.  
  100. ; A widget called 'draw' is created:
  101.  
  102. draw = WIDGET_DRAW(base, $
  103.     /FRAME, $
  104.     /MOTION_EVENTS, $        ;generate LOTS of events
  105.     UVALUE = 'DRAW_WIN_EVENT', $
  106.     RETAIN = 2, $            ;make sure window redraws when covered
  107.     XSIZE = x_size, $
  108.     YSIZE = y_size)
  109.  
  110. hint_label = WIDGET_LABEL(base, /FRAME, $
  111.     VALUE='Move Cursor in Draw Window')
  112.  
  113. ; Create the labels that will display the current x and y
  114. ; coordinates, leaving the value blank for now:
  115.  
  116. x_label = WIDGET_LABEL(base, /FRAME, /DYNAMIC_RESIZE, $
  117.         VALUE='X Coordinate: ')
  118.  
  119. y_label = WIDGET_LABEL(base, /FRAME, /DYNAMIC_RESIZE, $
  120.         VALUE='Y Coordinate: ')
  121.  
  122. ; Realize the widgets:
  123. WIDGET_CONTROL, base, /REALIZE
  124.  
  125. ; Get the window number from the draw widget.  This can only be done
  126. ; after the widget has been realized:
  127.  
  128. WIDGET_CONTROL, draw, GET_VALUE=win_num
  129.  
  130. ; Use TVSCL to display an image in the draw widget.  Set the window for
  131. ; the TVSCL command since there may be other draw windows.
  132.  
  133. WSET, win_num
  134. orig_image = DIST(50)
  135. TVSCL, REBIN(orig_image, x_size, y_size)
  136.  
  137. WSET, swin            ; Restore the original window
  138.  
  139. ; Hand off control of the widget to the XMANAGER:
  140. XMANAGER, "wmotion", base, GROUP_LEADER=GROUP, /NO_BLOCK
  141.  
  142.  
  143. END
  144.  
  145.  
  146.